import os
import ast

tab = ' ' * 4
line = '\n'

def convert_value(value, tar_type):
    if tar_type == 'int':
        return int(value)
    elif tar_type == 'float':
        return float(value)
    elif tar_type in {'string', "text"}:
        return str(value)
    elif tar_type == 'bool':
        return bool(value)
    elif tar_type == 'list':
        return conv_to_struct(value) if value else []
    elif tar_type == 'dict':
        return conv_to_struct(value) if value else {}
    elif tar_type == "note":
        return value if value else ""

def ensure_file_path(file_path):
    file_dir = os.path.dirname(file_path)
    if not os.path.exists(file_dir):
        os.makedirs(file_dir)

def write_to_file(file_path, content):
    ensure_file_path(file_path)
    with open(file_path, 'w', encoding='utf-8') as file:
        file.write(content)

def read_from_file(file_path):
    with open(file_path, 'r', encoding='utf-8') as file:
        return file.read()

def conv_to_struct(content):
    return ast.literal_eval(content)

def conv_to_string(struct):
    return str(struct)


def get_dir_files(dir_path, ext, file_list=None):
    if file_list is None:
        file_list = []
    
    for root, dirs, files in os.walk(dir_path):
        for file in files:
            if file.endswith(ext):
                file_list.append(os.path.join(root, file))
    return file_list